package com.waste.game.controller;

import com.waste.game.MyAnnotation.PassToken;
import com.waste.game.dao.*;
import com.waste.game.entity.entitiytv.*;
import com.waste.game.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
public class VideoHomeController {

    @Autowired
    private VideoAllDao videoAllDao;
    @Autowired
    private VideoHomeTopTvDao videoHomeTopTvDao;
    @Autowired
    private VideoHomeLbtDao videoHomeLbtDao;
    @Autowired
    private VideoHomeUpTimeListDao videoHomeUpTimeListDao;
    @Autowired
    private VideoHomeHotTvListDao videoHomeHotTvListDao;
    @Autowired
    private RedisService redisService;

    @RequestMapping ("/api/tv/{pageNum}/{pageSize}")
    public Object getHotTvList(@PathVariable(value = "pageNum") Integer pageNum,@PathVariable(value = "pageSize") Integer pageSize){
        boolean tvListKry = redisService.exists("tvList");
        if (tvListKry){
//            System.out.println("缓存拿取");
            Object obj = redisService.get("tvList");
            return obj;
        }else {
//            System.out.println("数据库拿取");
            List<VideoHotTvListBean> tvlist = videoHomeHotTvListDao.getHotTvBang(pageNum,pageSize);
            redisService.set("tvList",tvlist,10L, TimeUnit.MINUTES);
            return tvlist;
        }
//        return videoHomeHotTvListDao.getHotTvBang(pageNum,pageSize);
    }
//    @RequestMapping("/tv/homeTV/{tvName}")
//    public TvTitleBean getTvUrl(@PathVariable(value = "tvName") String tvName){
//        return tvListMapper.getTvUrl(tvName);
//    }
    @RequestMapping("/api/tv/TvUpTime/{day}/{start}/{end}")
    public List<VideoUpTimeBean> getTvUpTime(@PathVariable(value = "day") Integer day,@PathVariable(value = "start") Integer start,@PathVariable(value = "end") Integer end){
       return videoHomeUpTimeListDao.getTvUpTime(day,start,end);
    }
    @RequestMapping("/api/tv/lbt")
        public Object getLbt(){
        boolean LbtKry = redisService.exists("Lbt");
        if (LbtKry){
//            System.out.println("缓存拿取");
            Object obj = redisService.get("Lbt");
            return obj;
        }else {
//            System.out.println("数据库拿取");
            List<VideoLbtBean> lbt = videoHomeLbtDao.getLbt();
            redisService.set("Lbt",lbt,10L, TimeUnit.MINUTES);
            return lbt;
        }
//        return videoHomeLbtDao.getLbt();
    }
    @RequestMapping("/api/tv/videotop")
    public List<VideoTopBean> getVideoTopList(){
        return videoHomeTopTvDao.getVideoTopList();
    }
    @GetMapping("/api/homeDoLike")
    public List<VideoAllBean> getDoLike(){
        return videoAllDao.getDoLike();
    }
}
